﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineMovieTicket.Services.IServices;
using OnlineMovieTicket.Services.Services;
using OnlineMovieTicket.Model;
using System.IO;

namespace OnlineMovieTicket.WebForms.UserControl
{
    public partial class MoviesShowing : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                tabMovieShow.ActiveTabIndex = 0;
                tabMovieShow.ActiveTab.BackColor = System.Drawing.Color.SeaGreen;
                
                IMoviesService movieSrv = new MoviesService();
                IList<Model.Movies> movies = movieSrv.GetNowShowingMovies();
                dlMovieShow.DataSource = movies;
                dlMovieShow.DataBind();


                for (int i = 0; i < dlMovieShow.Items.Count; i++)
                {                   
                    ((Image)dlMovieShow.Items[i].FindControl("imgMovie")).ImageUrl = "ShowImage.aspx?id=" + movies[i].MovieCode;
                    ((Image)dlMovieShow.Items[i].FindControl("imgMovie")).Width = 110;
                    ((Image)dlMovieShow.Items[i].FindControl("imgMovie")).Height = 125;
                    
                }

                movies = movieSrv.GetCommingSoonMovies();
                dlCommingMovie.DataSource = movies;
                dlCommingMovie.DataBind();


                for (int i = 0; i < dlCommingMovie.Items.Count; i++)
                {                  
                    ((Image)dlCommingMovie.Items[i].FindControl("imgMovie")).ImageUrl = "ShowImage.aspx?id=" + movies[i].MovieCode;
                    ((Image)dlCommingMovie.Items[i].FindControl("imgMovie")).Width = 110;
                    ((Image)dlCommingMovie.Items[i].FindControl("imgMovie")).Height = 125;
                }
            }
        }

        protected void SelectItemCommand(object sender, DataListCommandEventArgs e)
        {           
            string movieCode = ((Label)dlMovieShow.Controls[e.Item.ItemIndex].FindControl("lblMovieCode")).Text;
            Response.Redirect("Movies/MovieDetails.aspx?MVCode=" + movieCode);
            
        }

        protected void SelectCommingSoonMovie(object source, DataListCommandEventArgs e)
        {
            string movieCode = ((Label)dlCommingMovie.Controls[e.Item.ItemIndex].FindControl("lblMovieCode")).Text;
            Response.Redirect("Movies/MovieDetails.aspx?MVCode=" + movieCode);
        }
     
        
    }
}